package com.zjy.software.day8;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) throws ParseException {
        Date date = new Date(2021, 8, 3);
        System.out.println("date = " + date);
        Date currentDate = new Date();
        System.out.println("currentDate.getTime() = " + currentDate.getTime());
        System.out.println("new Date() = " + currentDate);

        // 找出下面循环所用的时间
        long start = System.currentTimeMillis();
//        for (int i = 0; i < 100000; i++) {
//            System.out.println(i);
//        }
        long end = System.currentTimeMillis();
        System.out.println("所用的时间：" + (end - start));

        //日期不能直接跟字符串转化,有可能线程不安全,建议不用,用时间SimpleDateFormat
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("simpleDateFormat.format(currentDate) = " + simpleDateFormat.format(currentDate));

        String dateStr = "2023-08-03 14:30:30";
        Date parse = simpleDateFormat.parse(dateStr);
        System.out.println("parse = " + parse);


    }
}
